package com.hmdp.askPack.controller;

import com.hmdp.dto.LoginFormDTO;
import com.hmdp.dto.Result;
import com.hmdp.service.IUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController("ask-UserController")
@RequestMapping("/ask/user")
public class UserController {
    @Resource
    private IUserService userService;

    @PostMapping("/code")
    public Result sendCode(String phone, HttpSession session) {
        Result result = userService.sendCode1(phone, session);
        return result;
    }

    /**
     * 发送验证码：redis存储
     * @param phone
     * @return
     */
    @PostMapping("/code2redis")
    public Result sendCode2Redis(String phone) {
        Result result = userService.sendCode2Redis(phone);
        return result;
    }

    /**
     * 用户登录
     *
     * @param loginFormDTO
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginFormDTO loginFormDTO, HttpSession session) {
        System.out.println("session id : " + session.getId());
        return userService.login1(loginFormDTO, session);
    }

    @PostMapping("/loginRedis")
    public Result loginByRedis(LoginFormDTO dto, HttpSession session) {
        return userService.loginRedis(dto, session);
    }
}
